package cs342.uwosh.edu.ContactsApp;

import cs342.uwosh.edu.ContactsApp.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.EditText;

public class AddContact extends Activity {
	
	private String fName, lName, cPhone, hPhone, aPhone, address, email, comment;
	private ContactsDataSource db;
	private EditText fNameEdit, lNameEdit, cPhoneEdit, hPhoneEdit, aPhoneEdit, addressEdit, emailEdit, commentEdit;
	

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add);
        fNameEdit = (EditText) findViewById(R.id.firstNameEditText);
    	lNameEdit = (EditText) findViewById(R.id.lastNameEditText);
    	cPhoneEdit = (EditText) findViewById(R.id.cellPhoneEditText);
    	hPhoneEdit = (EditText) findViewById(R.id.homePhoneEditText);
    	aPhoneEdit = (EditText) findViewById(R.id.altPhoneEditText);
    	addressEdit = (EditText) findViewById(R.id.addressEditText);
    	emailEdit = (EditText) findViewById(R.id.emailEditText);
    	commentEdit = (EditText) findViewById(R.id.commentEditText);
//    	fNameEdit.setOnKeyListener(new OnKeyListener() {
//    	    public boolean onKey(View v, int keyCode, KeyEvent event) {
//    	        fName = fNameEdit.getText().toString();
//    	        return true;
//    	    }
//    	});
//    	lNameEdit.setOnKeyListener(new OnKeyListener() {
//    	    public boolean onKey(View v, int keyCode, KeyEvent event) {
//    	        lName = lNameEdit.getText().toString();
//    	        return true;
//    	    }
//    	});
//    	cPhoneEdit.setOnKeyListener(new OnKeyListener() {
//    	    public boolean onKey(View v, int keyCode, KeyEvent event) {
//    	    	cPhone = cPhoneEdit.getText().toString();
//    	        return true;
//    	    }
//    	});
//    	hPhoneEdit.setOnKeyListener(new OnKeyListener() {
//    	    public boolean onKey(View v, int keyCode, KeyEvent event) {
//    	    	hPhone = hPhoneEdit.getText().toString();
//    	        return true;
//    	    }
//    	});
//    	aPhoneEdit.setOnKeyListener(new OnKeyListener() {
//    	    public boolean onKey(View v, int keyCode, KeyEvent event) {
//    	        aPhone = aPhoneEdit.getText().toString();
//    	        return true;
//    	    }
//    	});
//    	addressEdit.setOnKeyListener(new OnKeyListener() {
//    	    public boolean onKey(View v, int keyCode, KeyEvent event) {
//    	        address = addressEdit.getText().toString();
//    	        return true;
//    	    }
//    	});
//    	emailEdit.setOnKeyListener(new OnKeyListener() {
//    	    public boolean onKey(View v, int keyCode, KeyEvent event) {
//    	        email = emailEdit.getText().toString();
//    	        return true;
//    	    }
//    	});
//    	commentEdit.setOnKeyListener(new OnKeyListener() {
//    	    public boolean onKey(View v, int keyCode, KeyEvent event) {
//    	        comment = commentEdit.getText().toString();
//    	        return true;
//    	    }
//    	});
    	
    	db = new ContactsDataSource(this);
    }
    
    public void submit(View view) {
    	long id = 0;
    	Contact contact = new Contact(id = (long)(Math.random()*10000),fNameEdit.getText() + " " + lNameEdit.getText(), addressEdit.getText().toString(), hPhoneEdit.getText().toString(), cPhoneEdit.getText().toString(), aPhoneEdit.getText().toString(), emailEdit.getText().toString(), commentEdit.getText().toString());
    	//System.out.println(contact);
    	db.open();
    	contact = db.createContact(contact);
    	//contact = db.getContact(contact.getID());
    	//System.out.println(contact);
    	db.close();
    	
    	
    	Intent i = new Intent(this, ContactsActivity.class);
    	startActivity(i);
    }
    
}